package leetcode77双周赛;

public class Two {
	public static void main(String []args) {
		int nums [] = {2,5,3,9,5,3};
		System.out.println(solution(nums));
	
	}
	static int solution(int nums []) {
		long ans  = Integer.MAX_VALUE;
		int index = -1;
		long preSum [] = new long [nums.length + 1];
		for(int i = 0 ;i < nums.length; i++) {
			preSum[i + 1] = nums[i] + preSum[i];
//			System.out.println(preSum[i + 1]);
		}
		int len = nums.length;
		for(int i = 0;i < nums.length - 1; i++) {	
			long right = (preSum[len] - preSum[i + 1]) / (len - i -1) ;
			long left = preSum[i + 1] / (i + 1);
			long temp = Math.abs(left - right );
			System.out.println(temp);
			if(ans > temp) {
				ans = temp;
				index = i;
			}
		}
		
		return ans > preSum[len] /len ? len - 1: index;
	}

}
